<?php

namespace Home\Controller;
use Think\Controller;

class PayApiController extends Controller{

    public function _initialize(){
        vendor("Qrcode.qrcode");
    }


    /**
     * @func 建设银行二维码支付
     * @param money 支付金额
     * @author LX
     * @date 2018-8-21
     * @return JSON
     */
    public function CCBPay($money,$orderid){
        $param=C('CCB');
        $param['ORDERID']=$orderid;
        $param['PAYMENT']=$money;
        //$param['PAYMENT']=0.01;
        $param['CURCODE']='01';                //币种
        $param['TXCODE']='530550';              //交易码
        $param['REMARK1']='';
        $param['REMARK2']='';
        $param['RETURNTYPE']=3;
        $param['TIMEOUT']='';
        $param['PUB']=substr(C('CCBKEY.PUBLICKEY'),(strlen(C('CCBKEY.PUBLICKEY'))-30));
        $param_str = http_build_query($param);          //加密字串
        $param['MAC']=md5($param_str);
        $param_str = http_build_query($param);          //发送参数
        $url = "https://ibsbjstar.ccb.com.cn/CCBIS/ccbMain?CCB_IBSVersion=V6";
        $result = doPost($url,$param_str);
        if($result){
            $ccb_result=json_decode($result,true);
            if($ccb_result['SUCCESS']){
                $param_result=doPost($ccb_result['PAYURL']);
                $canshu=json_decode($param_result,true);
                if($canshu['SUCCESS']) {
                    $pay_urltext = urldecode($canshu['QRURL']);
                    $level = 0;
                    $size = 10;
                    $padding = 1;
                    $result_weixin = \QRcode::png($pay_urltext, FALSE, $level, $size, $padding, false, true);
                    datamsg(1,'获取成功',$result_weixin);
                }else{
                    datamsg(0,'返回链接错误','');
                }
            }else{
                datamsg(0,'请求出错','');
            }
        }else{
            datamsg(0,'请求失败','');
        }
    }


    /**
     * @func支付查询接口 暂时没有用到
     */
    public function queryCCBPayorder()
    {
        $MERCHANTID='105000048165107';  //商户代码
        $BRANCHID='420000000';          //分行代码
        $POSID='023119420';   //商户柜台代码
        $ORDERDATE='20180822'; //与ORDERID必须有一个输入
        $BEGORDERTIME='00:00:00';//订单开始时间 非
        $ENDORDERTIME='23:59:59';//订单结束时间
        $ORDERID='';
        $QUPWD='xyz98765';//主管或操作员的登录密码
        $TXCODE='410408';//交易码
        $TYPE=0;
        $KIND=1;   //流水状态
        $STATUS=3; //交易状态
        $SEL_TYPE=3;//查询方式 1页面，2文件形式，3xml
        $PAGE=1;//查询页面
        $OPERATOR="";
        $CHANNEL='';
        $param_str="MERCHANTID=".$MERCHANTID."&BRANCHID=".$BRANCHID."&POSID=".$POSID."&ORDERDATE=".$ORDERDATE."&BEGORDERTIME=".$BEGORDERTIME."&ENDORDERTIME=".$ENDORDERTIME."&ORDERID=".$ORDERID."&QUPWD=&TXCODE=".$TXCODE."&TYPE=".$TYPE."&KIND=".$KIND."&STATUS=".$STATUS."&SEL_TYPE=".$SEL_TYPE."&PAGE=".$PAGE."&OPERATOR=".$OPERATOR."&CHANNEL=".$CHANNEL;

        $param['MERCHANTID']='105000048165107';  //商户代码
        $param['BRANCHID']='420000000';          //分行代码
        $param['POSID']='023119420';   //商户柜台代码
        $param['ORDERDATE']='20180822'; //与ORDERID必须有一个输入
        $param['BEGORDERTIME']='00:00:00';//订单开始时间 非
        $param['ENDORDERTIME']='23:59:59';//订单结束时间
//        $param['BEGORDERID']='';
//        $param['ENDORDERID']='';
        $param['ORDERID']='';
        $param['QUPWD']='Xyz964713';//主管或操作员的登录密码
        $param['TXCODE']='410408';//交易码
        $param['TYPE']=0;
        $param['KIND']=1;   //流水状态
        $param['STATUS']=3; //交易状态
        $param['SEL_TYPE']=3;//查询方式 1页面，2文件形式，3xml
        $param['PAGE']=1;//查询页面
        $param['OPERATOR']='';
        $param['CHANNEL']='';
        $param['MAC']=md5($param_str);
        $bankURL="https://ibsbjstar.ccb.com.cn/CCBIS/ccbMain?";
        $myparam_str = http_build_query($param);          //发送参数
        //echo $myparam_str;die();
        $result=doPost($bankURL,$myparam_str);
        dump($result);
    }


    /**
     * 异步回调通知
     */
    public static function returnapi(){
        $getdata = I('get.');
        return $getdata;
    }





}